//
//  SystemSettingViewController.m
//  MobileOffice
//
//  Created by jjkj on 16/10/19.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "SystemSettingViewController.h"
#import "PersonCenterTableViewCell.h"
#import "IdeasFeedbackViewController.h"
#import "CompanyIntroduViewController.h"
#import "PromptionViewController.h"
#import "UpdateInfoViewController.h"

@interface SystemSettingViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *_tableView;
    NSArray *_dataArr;//功能数组
    NSArray *_imageArr;//图片数组
}
@end

@implementation SystemSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setLeftBackNavigation];
    [self setRightBackNavigation];
    [self setNavigationTitle:@"系统设置"];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(postIdeasMessage:) name:@"postIdeasMessage" object:nil];
    [self creatView];
    // Do any additional setup after loading the view.
}
#pragma mark -creatTableView
- (void)creatView{
    _dataArr=@[@"意见反馈",@"版本信息",@"关于我们"];
    _imageArr=@[@"k_ic_opinion@2x",@"k_system@2x",@"k_we@2x"];
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT-64)style:UITableViewStylePlain];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.scrollEnabled=NO;
    //取消多余的行
    _tableView.tableFooterView = [UIView new];
    _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableView];
}
#pragma mark -tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return _dataArr.count;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *cellID=@"cellID";
    PersonCenterTableViewCell *cell=[[PersonCenterTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
    cell.contentView.backgroundColor=[UIColor whiteColor];
    cell.myTitle.textColor=[UIColor blackColor];
    cell.headImageView.frame=CGRectMake(10, 15, 30, 30);
    if (indexPath.section==0) {
        cell.myTitle.text = _dataArr[indexPath.row];
        
        cell.headImageView.image=[UIImage imageNamed:_imageArr[indexPath.row]];
        if (indexPath.row<2) {
            //增加下划线
            UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(0, 59, IPHONE_WIDTH, 1)];
            line.backgroundColor=BACKCOLOR_GRAY;
            [cell.contentView addSubview:line];
        }
        if (indexPath.row==1) {
            //版本号
            UILabel *systemCount=[[UILabel alloc]initWithFrame:CGRectMake(cell.myTitle.x+cell.myTitle.width-10, cell.myTitle.y, IPHONE_WIDTH-(cell.myTitle.x+cell.myTitle.width-10)-40, cell.myTitle.height)];
            systemCount.font=FONT_12;
            systemCount.textColor=[UIColor lightGrayColor];
            systemCount.textAlignment=NSTextAlignmentRight;
            NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
            systemCount.text=[infoDictionary objectForKey:@"CFBundleShortVersionString"];
            //systemCount.backgroundColor=[UIColor redColor];
            [cell.contentView addSubview:systemCount];
        }
    }else{
        cell.myTitle.text = @"提示设置";
        
        cell.headImageView.image=[UIImage imageNamed:@"k_hint@2x"];
        UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(0, 59, IPHONE_WIDTH, 1)];
        line.backgroundColor=BACKCOLOR_GRAY;
        [cell.contentView addSubview:line];
    }
    //        cell.titleLabel.text = [MyControl getAccountNowName];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        return cell;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 60;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
//    if (section==0) {
//        return 0;
//    }
    return 30;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            //意见反馈
            IdeasFeedbackViewController *ideas=[IdeasFeedbackViewController new];
            [self.navigationController pushViewController:ideas animated:YES];
        }else if (indexPath.row==2){
            //关于我们
            CompanyIntroduViewController *company=[CompanyIntroduViewController new];
            [self.navigationController pushViewController:company animated:YES];
        }else{
            //版本信息
            UpdateInfoViewController *update=[UpdateInfoViewController new];
            [self.navigationController pushViewController:update animated:YES];
        }
    }else if (indexPath.section==1){
        //提示设置
        PromptionViewController *promption=[PromptionViewController new];
        [self.navigationController pushViewController:promption animated:YES];
    }
}

- (void)postIdeasMessage:(NSNotification *)notification{
    NSDictionary *dict=[notification userInfo];
    [LZXHelper postMessageWithText:dict[@"userInfo"] View:self.view];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
